package com.cdinternationalcompany.syhapp.push.oppo

import android.content.Context
import android.util.Log
import com.cdinternationalcompany.syhapp.push.Constants
import com.cdinternationalcompany.syhapp.push.NotificationHelper
import com.cdinternationalcompany.syhapp.push.hw.HMSPushService
import com.google.gson.Gson
import com.heytap.msp.push.mode.DataMessage
import com.heytap.msp.push.service.CompatibleDataMessageCallbackService
import com.heytap.msp.push.service.DataMessageCallbackService
import org.json.JSONObject
import java.lang.Exception

class OppoQPushService : DataMessageCallbackService() {
    companion object {
        val TAG = "${Constants.tag}.Oppo"
    }

    override fun processMessage(context: Context?, message: DataMessage) {
        Log.d(TAG, "Q:processMessage -> ${message.content}")
//        Log.d(HMSPushService.TAG, " HMSPushService#onMessageReceived ->  ${Gson().toJson(msg)}")
        try {
            val json = JSONObject(message.content)
            Log.d(OppoQPushService.TAG, "processMessage#json ->  $json")
            NotificationHelper.showNotification(
                    application,
                    json.getString("title"),
                    json.getString("content"),
                    JSONObject().apply {
                        put("url", json.getString("url"))
                    }.toString()
            )
        } catch (e: Exception) {
            e.printStackTrace()
        }
    }

}